from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError


class LotDatecodeSummary(models.TransientModel):
    _inherit = 's.lot.datecode.summary.wiz'

    def action_update_package_multi(self):
        """增加Ecr锁单校验，判断是否能够出货"""
        if not self:
            return
        lot_ids = self.filtered(lambda r: r.qty > 0).mapped('lot_ids')
        if lot_ids:
            production_ids = self.env['mrp.production'].sudo().search([('lot_producing_id', 'in', lot_ids.ids)]).filtered(lambda x: x.s_disable_delivery)
            if production_ids:
                lot_name = ','.join([p.lot_producing_id.name for p in production_ids])
                raise ValidationError(_('Batch number: {} has been prohibited from shipment').format(lot_name))
        else:
            pass
        super().action_update_package_multi()
        return {'type': 'ir.actions.act_window_close'}
